package com.version1.diabeco.ui.ajustes.medicamento;


import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.version1.diabeco.R;
import com.version1.diabeco.model.ajustes.medicamento.Medicamento;


/**
 * Adapter para visualizacion de registros en ListView con el siguiente formato: 
 * 
 * [Imagen]  [Medicamento] 		|
 * 
 */

public class MedicamentoAdapter extends ArrayAdapter<Medicamento> {
	private final Context context;
	private final List<Medicamento> values;

	public MedicamentoAdapter(Context context, int resource, List<Medicamento> values) {
		super(context, resource, values);
		this.context = context;
		this.values = values;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.activity_medicamento_fila, parent, false);
		
		Medicamento medicamento = values.get(position);
		
		TextView textView = (TextView) rowView.findViewById(R.id.textViewMedicamentoFilaDescripcion);
		textView.setText(medicamento.getDescripcion().toString());

		ImageView imgView =  (ImageView) rowView.findViewById(R.id.imageViewMedicamento);
		imgView.setImageResource(medicamento.getIconResourceId());

		return rowView;
	}
}

